var paymentOrderNo;
var $table = $("#costdetailTab");
$(function () {
	//时间控件

    
    paymentOrderNo = $.getUrlParam("paymentOrderNo");
    initTable();
});

function initTable() {
    $table.bootstrapTable({
        dataType: "json",
        showColumns: true, 	
        pagination: true, //分页
        striped: true,
        cache: false,	//是否使用缓存，默认是true
        pageSize: 10,
        pageNumber: 1,
        queryParamsType: 'limit',
        smartDisplay: true,
        sidePagination: "server",
        method: "get",	//使用post提交
        url: '../costsharing/getEveryLastCutPayInfo.htm?paymentOrderNo='+paymentOrderNo,
        contentType: 'application/x-www-form-urlencoded;charset=UTF-8',
        columns: [
            {
                title: "序号",
                align: 'center',
                formatter:function(value,row,index){
                    return index + 1;
                }
            },
            {
                title: "支付订单号",
                field: "paymentOrderNo",
                align: 'center',
                valign: 'middle'
            },
            {
            	title: "分账订单号",
                field: "orderNo",
                align: 'center',
                valign: 'middle'
            },
            {
            	title: "账户号",
                field: "accountNo",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "交易金额",
                field: "amount",
                align: 'center',
                valign: 'middle'
            },
            {
            	title: "分账订单号",
                field: "transNo",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "分账状态",
                field: "status",
                align: 'center',
                formatter: function(value, row, index){
                    var status = "-";
                    if(row.status =="00"){
                    	status = '<span style="color:#5DBB5D;">分账成功</span>';
                    }else if(row.status == "01"){
                    	status ='<span style="color:#E25550;">分账失败</span>';
                    }
                    else if(row.status == "02"){
                    	status ='<span style="color:#F59206;">分账已撤销</span>';
                    }
                    else if(row.status == "03"){
                    	status ='<span style="color:#3CA2C0;">分账待请求</span>';
                    }
                    else if(row.status == "04"){
                    	status ='<span style="color:#0078CC;">分账处理中</span>';
                    }
                    return status;
                }
            },
            {
                title: "账户名",
                field: "cpName",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "编号",
                field: "cpNum",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "类型",
                field: "cpType",
                align: 'center',
                formatter: function(value, row, index){
                    var cpType = "-";
                    if(row.cpType == "A"){
                    	cpType = '<span style="color:#E25550;">平台</span>';
                    }else if(row.cpType == "B"){
                    	cpType ='<span style="color:#5DBB5D;">司机</span>';
                    }else if(row.cpType == "C"){
                    	cpType ='<span style="color:#0078CC;">企业</span>';
                    }
                    return cpType;
                }
            },
            {
                title: "操作",
                align: 'center',
                formatter: function (value, row, index) {
                    var d = '-';
                    var e = '-';
                    if (row.status == "00"){
                    	d = '<button class="btn btn-xs btn-warning" type="button" onclick="accountrevoke(\'' + row.paymentOrderNo + '\',\'' + row.amount + '\',\'' + row.transNo +'\',\'' + row.cpType +  '\',\'' + row.accountNo + '\')">分账撤销 </button> ';
                    }
                    if (row.status != "02"){
                    	e = '<button class="btn btn-xs btn-info" type="button" onclick="accountsearch(\'' + row.transNo +'\',\'' + row.accountNo +  '\',\'' + row.status + '\')">分账查询 </button> ';
                    }
                    return e+d;
                }
            }
        ],
        onClickRow: function(row, $element, field){	//当点击某一行时，该行背景颜色改变
        	var trObj = $($element[0]);
        	var dataIndex = trObj.attr('data-index');
        	$("tr[data-index != '" + dataIndex + "']").removeAttr('style');
        	trObj.attr('style', 'background: #B4EEB4');
        }
    });
}

//分账撤销操作
function accountrevoke(paymentOrderNo,amount,transNo,cpType,accountNo) {
	var saveDataAry = [];  
	var selectContent = {"amount":amount,"transNo":transNo ,"cpType":cpType,"accountNo":accountNo};
	saveDataAry.push(selectContent); 
    layer.confirm('你确定要再撤销分账么', { 
        btn: ['确定', '取消'] //按钮
    }, function () {
        $.ajax({
            url: "../costsharing/batchCutPaycpRevoke.htm",
            cache: false,
            type: "post",
            dataType: "json",
            /*contentType:"application/json",*/
            data:{'paymentOrderNo': paymentOrderNo,'jsonStr':JSON.stringify(saveDataAry)},
            success: function (result) {
               if (result.status == 0) {
                    layer.msg(result.message, {icon: 1});
                    $table.bootstrapTable('refresh', {url: '../costsharing/getEveryLastCutPayInfo.htm?paymentOrderNo=' + paymentOrderNo});
                    return;
                }
                layer.msg(result.message, {icon: 2});
          }
        });
    }, function () {});
}

//分账查询
function accountsearch(transNo,accountNo,status) {
	$.ajax({
        url: "../costsharing/cutPayCpQuery.htm",
        cache: false,
        type: "post",
        dataType: "json",
        data:{'transNo': transNo,'accountNo':accountNo,'status':status},
        success: function (result) {
        	var data = result.data;
        	var status="";
			if(result.status=="0"){
				if(data.status =="00"){
	        		status = "成功"
	        	}else if(data.status =="01"){
	        		status = "失败"
	        	}
	        	else if(data.status =="02"){
	        		status = "已撤销"
	        	}
	        	else if(data.status =="03"){
	        		status = "待请求"
	        	}
	        	else if(data.status =="04"){
	        		status = "处理中"
	        	}
	        	layer.alert("分账状态：" + status+"</br>"+"订单号："+data.orderNo, {
	        		  skin: 'layui-layer-molv' //样式类名
	        		  ,closeBtn: 0
	        		});   		
        	}else if(result.status=="1"){
        		layer.alert(""+ result.message, {
	        		  skin: 'layui-layer-molv' //样式类名
	        		  ,closeBtn: 0
	        		});  
        	}
        	
        }   
    });
	
}


